﻿
namespace ToRTalent {
    using System;
    using System.Linq;
    using System.Windows;
    using System.Windows.Controls;
    using System.Windows.Input;
    using System.Windows.Media.Imaging;

    public partial class ClassButton : UserControl {
        public ClassButton() {
            InitializeComponent();
        }

        private const string _advClassPropertyName = "AdvClass";

        /// <summary>
        /// Property variable for the XAML AdvClass property
        /// </summary>
        public static readonly DependencyProperty AdvClassProperty = DependencyProperty.Register( _advClassPropertyName, typeof( string ),
                                                                                                  typeof( ClassButton ), new PropertyMetadata( String.Empty ) );

        private const string _classBgPropertyName = "ClassBtnBg";

        /// <summary>
        /// Property variable for the XAML ClassBtnBg property
        /// </summary>
        public static readonly DependencyProperty ClassBgProperty = DependencyProperty.Register( _classBgPropertyName, typeof( string ),
                                typeof( ClassButton ), new PropertyMetadata( String.Empty ) );

        private string[] _availClasses = { "Sentinel", "Guardian", "Shadow", "Sage", "Scoundrel", "Gunslinger", "Vanguard", "Commando",
                                           "Marauder", "Juggernaut", "Sorcerer", "Assassin", "Sniper", "Operative", "Mercenary", "Powertech" };

        /// <summary>
        /// Gets or sets the name of the advance class, used to select the correct
        /// label image
        /// </summary>
        public string AdvClass {
            get { return ( string )GetValue( AdvClassProperty ); }
            set {
                SetValue( AdvClassProperty, value );
                if( _availClasses.Contains( value ) )
                    nameImg.Source = new BitmapImage( new Uri( @"Images/Buttons/Text/" + value + @"Text.png", UriKind.Relative ) );
            }
        }

        private string _dirPath = @"Images/Buttons/";
        private string _imgRestSuffix = "Rest.png";
        private string _imgHoverSuffix = "Hover.png";

        /// <summary>
        /// Gets or sets the class button background depending on if the class this button
        /// represents is Empire or Republic
        /// </summary>
        public string ClassBg {
            get { return ( string )GetValue( ClassBgProperty ); }
            set {
                SetValue( ClassBgProperty, value );
                if( !String.IsNullOrWhiteSpace( value ) )
                    bgImg.Source = new BitmapImage( new Uri( _dirPath + ClassBg + _imgRestSuffix, UriKind.Relative ) );
            }
        }

        /// <summary>
        /// Starts the storyboard animation that shrinks the control
        /// </summary>
        public void StartAnimation() {
            ShrinkControl.Begin();
        }

        private void ClassButtonMouseHover( object sender, MouseEventArgs e ) {
            if( !String.IsNullOrEmpty( ClassBg ) )
                bgImg.Source = new BitmapImage( new Uri( _dirPath + ClassBg + _imgHoverSuffix, UriKind.Relative ) );
        }

        private void ClassButtonMouseLeave( object sender, MouseEventArgs e ) {
            if( !String.IsNullOrEmpty( ClassBg ) )
                bgImg.Source = new BitmapImage( new Uri( _dirPath + ClassBg + _imgRestSuffix, UriKind.Relative ) );
        }
    }
}
